package com.lh.music.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lh.music.R;
import com.lh.music.entity.Diantai;

import java.util.List;

/**
 * Created by a on 2016/11/4.
 */
public class GridViewAdapter extends BaseAdapter {
    private Context context;
    private List<Diantai>  mData;
    private int count;
    public GridViewAdapter(Context context, List<Diantai> mData) {
        this.context = context;
        this.mData = mData;
    }

    public GridViewAdapter(Context context, List<Diantai> mData, int count) {
        this.context = context;
        this.mData = mData;
        this.count = count;
    }

    @Override
    public int getCount() {
        return count;
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            holder=new ViewHolder();
            convertView= LayoutInflater.from(context).
                    inflate(R.layout.adapter_gridview,null);
            holder.tv= (TextView) convertView.findViewById(R.id.tv);
            holder.iv= (ImageView) convertView.findViewById(R.id.iv);
            //绑定
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        //绑定数据

            holder.tv.setText(mData.get(position).getName());
            Glide.with(context)
                    .load(mData.get(position).getThumb())
                    .placeholder(R.mipmap.a9d)
                    .crossFade()
                    .centerCrop()
                    .into(holder.iv);



        return convertView;
    }
    static class ViewHolder{
        TextView tv;
        ImageView iv;
    }
}
